package aidturith.ihm.component;

import java.awt.FlowLayout;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.RenderingHints.Key;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Miniature extends JPanel {

	private static final long serialVersionUID = 1L;

	public Miniature(String path, Key key, Object value) throws IOException {
		BufferedImage myPicture = ImageIO.read(new File(path));
		BufferedImage tmp = new BufferedImage(150, 150, myPicture.getType());
		Graphics2D g = tmp.createGraphics();
		g.setRenderingHint(key, value);
		g.drawImage(myPicture, 0, 0, 150, 150, 0, 0, myPicture.getWidth(), myPicture.getHeight(), null);
		g.dispose();

		JLabel picLabel = new JLabel();
		picLabel.setIcon(new ImageIcon(tmp));
		//picLabel.setIcon(new ImageIcon(myPicture.getScaledInstance(100, 100, 0)));
		add(picLabel);
	}

	/*@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.drawImage(image, 0, 0, null); // see javadoc for more info on the parameters
	}*/

	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.setLayout(new FlowLayout());
		try {
			frame.add(new Miniature("C:\\Users\\admin\\Music\\Yuuhei Satellite\\Kachou Fuugetsu\\folder.jpg",
					RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC));
			frame.add(new Miniature("C:\\Users\\admin\\Music\\Yuuhei Satellite\\Kachou Fuugetsu\\folder.jpg",
					RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR));
			frame.add(new Miniature("C:\\Users\\admin\\Music\\Yuuhei Satellite\\Kachou Fuugetsu\\folder.jpg",
					RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR));
		} catch (IOException e) {
			e.printStackTrace();
		}
		frame.setVisible(true);
		frame.pack();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}


}